<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta name="description" content="学习shell脚本之前的基础知识"/>
    <meta name="keywords"
          content="nginx,freebsd,linux,mysql,shell,apache,centos,redhat,rhel,windows,sql,系统运维,IT运维,开源系统,开源系统运维"/>
    <title>学习 shell脚本之前的基础知识 </title>

</head>
<body bgcolor="#FFFFFF" text="#000000">
<div id="menu">
    <ul>
		<span style="FONT-SIZE: 10.5pt">

			<li><a href="index.htm" hidefocus="true" id="mn_list">linux入门教程</a></li>

		</span>
    </ul>
</div>
<p style="text-align: center;"><span style="font-family:'宋体';font-size:15pt;"><b>第十二章</b></span><span
        style="font-family:'Calibri';font-size:15pt;"><b> </b></span><span style="font-family:'宋体';font-size:15pt;"><b>学习</b></span><span
        style="font-family:'Calibri';font-size:15pt;"><b>	shell</b></span><span
        style="font-family:'宋体';font-size:15pt;"><b>脚本之前的基础知识</b></span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">	</span><span
        style="font-family:'宋体';font-size:10.5pt;">日常的</span><span
        style="font-family:'Calibri';font-size:10.5pt;">linux</span><span style="font-family:'宋体';font-size:10.5pt;">系统管理工作中必不可少的就是</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span style="font-family:'宋体';font-size:10.5pt;">脚本，如果不会写</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span style="font-family:'宋体';font-size:10.5pt;">脚本，那么你就不算一个合格的管理员</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span style="font-family:'宋体';font-size:10.5pt;">目前很多单位在招聘</span><span
        style="font-family:'Calibri';font-size:10.5pt;">linux</span><span style="font-family:'宋体';font-size:10.5pt;">系统管理员时，</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span style="font-family:'宋体';font-size:10.5pt;">脚本的编写是必考的项目</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span
        style="font-family:'宋体';font-size:10.5pt;">有的单位甚至用</span><span style="font-family:'Calibri';font-size:10.5pt;">shell</span><span
        style="font-family:'宋体';font-size:10.5pt;">脚本的编写能力来衡量这个</span><span
        style="font-family:'Calibri';font-size:10.5pt;">linux</span><span style="font-family:'宋体';font-size:10.5pt;">系统管理员的经验是否丰富</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span style="font-family:'宋体';font-size:10.5pt;">笔者讲这些的目的只有一个，那就是让你认真对待</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span style="font-family:'宋体';font-size:10.5pt;">脚本，从一开始就要把基础知识掌握牢固，然后要不断的练习，只要你</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span style="font-family:'宋体';font-size:10.5pt;">脚本写的好，相信你的</span><span
        style="font-family:'Calibri';font-size:10.5pt;">linux</span><span style="font-family:'宋体';font-size:10.5pt;">求职路就会轻松的多</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span style="font-family:'宋体';font-size:10.5pt;">笔者在这一章中并不会多么详细的介绍</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span style="font-family:'宋体';font-size:10.5pt;">脚本，而只是带你进入</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span style="font-family:'宋体';font-size:10.5pt;">脚本的世界，如果你很感兴趣那么请到网上下载相关的资料或者到书店购买相关书籍吧</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">	</span><span
        style="font-family:'宋体';font-size:10.5pt;">在学习</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell </span><span style="font-family:'宋体';font-size:10.5pt;">脚本之前，需要你了解很多关于</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span style="font-family:'宋体';font-size:10.5pt;">的知识，这些知识是编写</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span style="font-family:'宋体';font-size:10.5pt;">脚本的基础，所以希望你能够熟练的掌握</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>


<p><span style="font-family:'Calibri';font-size:10.5pt;"><b>【</b></span><span
        style="font-family:'宋体';font-size:10.5pt;"><b>什么是</b></span><span
        style="font-family:'Calibri';font-size:10.5pt;"><b>shell】</b></span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">	</span><span style="font-family:'宋体';font-size:10.5pt;">简单点理解，就是系统跟计算机硬件交互时使用的中间介质，它只是系统的一个工具</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span
        style="font-family:'宋体';font-size:10.5pt;">实际上，在</span><span style="font-family:'Calibri';font-size:10.5pt;">shell</span><span
        style="font-family:'宋体';font-size:10.5pt;">和计算机硬件之间还有一层东西那就是系统内核了</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span style="font-family:'宋体';font-size:10.5pt;">打个比方，如果把计算机硬件比作一个人的躯体，而系统内核则是人的大脑，至于</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span style="font-family:'宋体';font-size:10.5pt;">，把它比作人的五官似乎更加贴切些</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span style="font-family:'宋体';font-size:10.5pt;">回到计算机上来，用户直接面对的不是计算机硬件而是</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span style="font-family:'宋体';font-size:10.5pt;">，用户把指令告诉</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span
        style="font-family:'宋体';font-size:10.5pt;">，然后</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span style="font-family:'宋体';font-size:10.5pt;">再传输给系统内核，接着内核再去支配计算机硬件去执行各种操作</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">	</span><span style="font-family:'宋体';font-size:10.5pt;">笔者接触的</span><span
        style="font-family:'Calibri';font-size:10.5pt;">linux</span><span style="font-family:'宋体';font-size:10.5pt;">发布版本（</span><span
        style="font-family:'Calibri';font-size:10.5pt;">Redhat/CentOS</span><span
        style="font-family:'宋体';font-size:10.5pt;">）系统默认安装的</span><span style="font-family:'Calibri';font-size:10.5pt;">shell</span><span
        style="font-family:'宋体';font-size:10.5pt;">叫做</span><span
        style="font-family:'Calibri';font-size:10.5pt;">bash</span><span
        style="font-family:'宋体';font-size:10.5pt;">，即</span><span style="font-family:'Calibri';font-size:10.5pt;">Bourne Again Shell</span><span
        style="font-family:'宋体';font-size:10.5pt;">，它是</span><span
        style="font-family:'Calibri';font-size:10.5pt;">sh</span><span
        style="font-family:'宋体';font-size:10.5pt;">（</span><span style="font-family:'Calibri';font-size:10.5pt;">Bourne Shell</span><span
        style="font-family:'宋体';font-size:10.5pt;">）的增强版本</span><span style="font-family:'Calibri';font-size:10.5pt;">。Bourn Shell </span><span
        style="font-family:'宋体';font-size:10.5pt;">是最早行起来的一个</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span style="font-family:'宋体';font-size:10.5pt;">，创始人叫</span><span
        style="font-family:'Calibri';font-size:10.5pt;">Steven Bourne</span><span
        style="font-family:'宋体';font-size:10.5pt;">，为了纪念他所以叫做</span><span
        style="font-family:'Calibri';font-size:10.5pt;">Bourn Shell</span><span
        style="font-family:'宋体';font-size:10.5pt;">，检称</span><span
        style="font-family:'Calibri';font-size:10.5pt;">sh。</span><span
        style="font-family:'宋体';font-size:10.5pt;">那么这个</span><span
        style="font-family:'Calibri';font-size:10.5pt;">bash</span><span style="font-family:'宋体';font-size:10.5pt;">有什么特点呢？</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">	1</span><span style="font-family:'宋体';font-size:10.5pt;">）记录命令历史</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">	</span><span style="font-family:'宋体';font-size:10.5pt;">我们敲过的命令，</span><span
        style="font-family:'Calibri';font-size:10.5pt;">linux</span><span style="font-family:'宋体';font-size:10.5pt;">是会有记录的，预设可以记录</span><span
        style="font-family:'Calibri';font-size:10.5pt;">1000</span><span style="font-family:'宋体';font-size:10.5pt;">条历史命令</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span style="font-family:'宋体';font-size:10.5pt;">这些命令保存在用户的家目录中的</span><span
        style="font-family:'Calibri';font-size:10.5pt;">.bash_history</span><span
        style="font-family:'宋体';font-size:10.5pt;">文件中</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span style="font-family:'宋体';font-size:10.5pt;">有一点需要你知道的是，只有当用户正常退出当前</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span style="font-family:'宋体';font-size:10.5pt;">时，在当前</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span style="font-family:'宋体';font-size:10.5pt;">中运行的命令才会保存至</span><span
        style="font-family:'Calibri';font-size:10.5pt;">.bash_history</span><span
        style="font-family:'宋体';font-size:10.5pt;">文件中</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">	</span><span style="font-family:'宋体';font-size:10.5pt;">与命令历史有关的有一个有意思的字符那就是</span><span
        style="font-family:'Calibri';font-size:10.5pt;">”!”</span><span
        style="font-family:'宋体';font-size:10.5pt;">了</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span style="font-family:'宋体';font-size:10.5pt;">常用的有这么几个应用：（</span><span
        style="font-family:'Calibri';font-size:10.5pt;">1</span><span
        style="font-family:'宋体';font-size:10.5pt;">）</span><span
        style="font-family:'Calibri';font-size:10.5pt;">!! </span><span
        style="font-family:'宋体';font-size:10.5pt;">（连续两个</span><span
        style="font-family:'Calibri';font-size:10.5pt;">”!”</span><span style="font-family:'宋体';font-size:10.5pt;">），表示执行上一条指令；（</span><span
        style="font-family:'Calibri';font-size:10.5pt;">2</span><span
        style="font-family:'宋体';font-size:10.5pt;">）</span><span
        style="font-family:'Calibri';font-size:10.5pt;">!n</span><span
        style="font-family:'宋体';font-size:10.5pt;">（这里的</span><span
        style="font-family:'Calibri';font-size:10.5pt;">n</span><span style="font-family:'宋体';font-size:10.5pt;">是数字），表示执行命令历史中第</span><span
        style="font-family:'Calibri';font-size:10.5pt;">n</span><span
        style="font-family:'宋体';font-size:10.5pt;">条指令，例如</span><span style="font-family:'Calibri';font-size:10.5pt;">”!100”</span><span
        style="font-family:'宋体';font-size:10.5pt;">表示执行命令历史中第</span><span
        style="font-family:'Calibri';font-size:10.5pt;">100</span><span
        style="font-family:'宋体';font-size:10.5pt;">个命令；（</span><span
        style="font-family:'Calibri';font-size:10.5pt;">3</span><span
        style="font-family:'宋体';font-size:10.5pt;">）</span><span
        style="font-family:'Calibri';font-size:10.5pt;">!</span><span style="font-family:'宋体';font-size:10.5pt;">字符串（字符串大于等于</span><span
        style="font-family:'Calibri';font-size:10.5pt;">1</span><span
        style="font-family:'宋体';font-size:10.5pt;">），例如</span><span
        style="font-family:'Calibri';font-size:10.5pt;">!ta</span><span style="font-family:'宋体';font-size:10.5pt;">，表示执行命令历史中最近一次以</span><span
        style="font-family:'Calibri';font-size:10.5pt;">ta</span><span
        style="font-family:'宋体';font-size:10.5pt;">为开头的指令</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_1.png"></span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">	2</span><span style="font-family:'宋体';font-size:10.5pt;">）指令和文件名补全</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">	</span><span style="font-family:'宋体';font-size:10.5pt;">在本教程最开始笔者就介绍过这个功能了，记得吗？对了就是按</span><span
        style="font-family:'Calibri';font-size:10.5pt;">tab</span><span style="font-family:'宋体';font-size:10.5pt;">键，它可以帮你补全一个指令，也可以帮你补全一个路径或者一个文件名</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span
        style="font-family:'宋体';font-size:10.5pt;">连续按两次</span><span
        style="font-family:'Calibri';font-size:10.5pt;">tab</span><span style="font-family:'宋体';font-size:10.5pt;">键，系统则会把所有的指令或者文件名都列出来</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">	3</span><span style="font-family:'宋体';font-size:10.5pt;">）别名</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">	</span><span style="font-family:'宋体';font-size:10.5pt;">前面也出现过</span><span
        style="font-family:'Calibri';font-size:10.5pt;">alias</span><span style="font-family:'宋体';font-size:10.5pt;">的介绍，这个就是</span><span
        style="font-family:'Calibri';font-size:10.5pt;">bash</span><span style="font-family:'宋体';font-size:10.5pt;">所特有的功能之一了</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span
        style="font-family:'宋体';font-size:10.5pt;">我们可以通过</span><span style="font-family:'Calibri';font-size:10.5pt;">alias</span><span
        style="font-family:'宋体';font-size:10.5pt;">把一个常用的并且很长的指令别名一个简洁易记的指令</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span style="font-family:'宋体';font-size:10.5pt;">如果不想用了，还可以用</span><span
        style="font-family:'Calibri';font-size:10.5pt;">unalias</span><span style="font-family:'宋体';font-size:10.5pt;">解除别名功能</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span
        style="font-family:'宋体';font-size:10.5pt;">直接敲</span><span
        style="font-family:'Calibri';font-size:10.5pt;">alias</span><span style="font-family:'宋体';font-size:10.5pt;">会看到目前系统预设的</span><span
        style="font-family:'Calibri';font-size:10.5pt;">alias </span><span
        style="font-family:'宋体';font-size:10.5pt;">：</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_7.png">’]。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">	4</span><span style="font-family:'宋体';font-size:10.5pt;">）通配符</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">	</span><span
        style="font-family:'宋体';font-size:10.5pt;">在</span><span
        style="font-family:'Calibri';font-size:10.5pt;">bash</span><span style="font-family:'宋体';font-size:10.5pt;">下，可以使用</span><span
        style="font-family:'Calibri';font-size:10.5pt;">*</span><span style="font-family:'宋体';font-size:10.5pt;">来匹配零个或多个字符，而用</span><span
        style="font-family:'Calibri';font-size:10.5pt;">?</span><span
        style="font-family:'宋体';font-size:10.5pt;">匹配一个字符</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_8.png"></span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">	5</span><span style="font-family:'宋体';font-size:10.5pt;">）输入输出从定向</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">	</span><span style="font-family:'宋体';font-size:10.5pt;">输入重定向用于改变命令的输入，输出重定向用于改变命令的输出</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span style="font-family:'宋体';font-size:10.5pt;">输出重定向更为常用，它经常用于将命令的结果输入到文件中，而不是屏幕上</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span style="font-family:'宋体';font-size:10.5pt;">输入重定向的命令是</span><span
        style="font-family:'Calibri';font-size:10.5pt;">&lt;</span><span style="font-family:'宋体';font-size:10.5pt;">，输出重定向的命令是</span><span
        style="font-family:'Calibri';font-size:10.5pt;">&gt;</span><span style="font-family:'宋体';font-size:10.5pt;">，另外还有错误重定向</span><span
        style="font-family:'Calibri';font-size:10.5pt;">2&gt;</span><span style="font-family:'宋体';font-size:10.5pt;">，以及追加重定向</span><span
        style="font-family:'Calibri';font-size:10.5pt;">&gt;&gt;</span><span style="font-family:'宋体';font-size:10.5pt;">，稍后会详细介绍</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">	6</span><span style="font-family:'宋体';font-size:10.5pt;">）管道符</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">	</span><span style="font-family:'宋体';font-size:10.5pt;">前面已经提过过管道符</span><span
        style="font-family:'Calibri';font-size:10.5pt;">”|”</span><span style="font-family:'宋体';font-size:10.5pt;">，就是把前面的命令运行的结果丢给后面的命令</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">	7</span><span style="font-family:'宋体';font-size:10.5pt;">）作业控制</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">	</span><span style="font-family:'宋体';font-size:10.5pt;">当运行一个进程时，你可以使它暂停（按</span><span
        style="font-family:'Calibri';font-size:10.5pt;">Ctrl+z</span><span style="font-family:'宋体';font-size:10.5pt;">），然后使用</span><span
        style="font-family:'Calibri';font-size:10.5pt;">fg</span><span style="font-family:'宋体';font-size:10.5pt;">命令恢复它，利用</span><span
        style="font-family:'Calibri';font-size:10.5pt;">bg</span><span style="font-family:'宋体';font-size:10.5pt;">命令使他到后台运行，你也可以使它终止（按</span><span
        style="font-family:'Calibri';font-size:10.5pt;">Ctrl+c</span><span
        style="font-family:'宋体';font-size:10.5pt;">）</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><b>【</b></span><span
        style="font-family:'宋体';font-size:10.5pt;"><b>变量</b></span><span
        style="font-family:'Calibri';font-size:10.5pt;"><b>】</b></span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">	</span><span style="font-family:'宋体';font-size:10.5pt;">前面章节中笔者曾经介绍过环境变量</span><span
        style="font-family:'Calibri';font-size:10.5pt;">PATH</span><span style="font-family:'宋体';font-size:10.5pt;">，这个环境变量就是</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span style="font-family:'宋体';font-size:10.5pt;">预设的一个变量，通常</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span style="font-family:'宋体';font-size:10.5pt;">预设的变量都是大写的</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span style="font-family:'宋体';font-size:10.5pt;">变量，说简单点就是使用一个较简单的字符串来替代某些具有特殊意义的设定以及数据</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span
        style="font-family:'宋体';font-size:10.5pt;">就拿</span><span
        style="font-family:'Calibri';font-size:10.5pt;">PATH</span><span style="font-family:'宋体';font-size:10.5pt;">来讲，这个</span><span
        style="font-family:'Calibri';font-size:10.5pt;">PATH</span><span style="font-family:'宋体';font-size:10.5pt;">就代替了所有常用命令的绝对路径的设定</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span
        style="font-family:'宋体';font-size:10.5pt;">因为有了</span><span
        style="font-family:'Calibri';font-size:10.5pt;">PATH</span><span style="font-family:'宋体';font-size:10.5pt;">这个变量，所以我们运行某个命令时不再去输入全局路径，直接敲命令名即可</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span
        style="font-family:'宋体';font-size:10.5pt;">你可以使用</span><span style="font-family:'Calibri';font-size:10.5pt;">echo</span><span
        style="font-family:'宋体';font-size:10.5pt;">命令显示变量的值</span><span style="font-family:'Calibri';font-size:10.5pt;">。</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_9.png"></span></p>
<p><span style="font-family:'宋体';font-size:10.5pt;">除了</span><span style="font-family:'Calibri';font-size:10.5pt;">PATH, HOME, LOGNAME</span><span
        style="font-family:'宋体';font-size:10.5pt;">外，系统预设的环境变量还有哪些呢？</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_10.png">下面笔者简单介绍一下常见的环境变量：</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">PATH	</span><span
        style="font-family:'宋体';font-size:10.5pt;">决定了</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span style="font-family:'宋体';font-size:10.5pt;">将到哪些目录中寻找命令或程序</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">HOME	</span><span
        style="font-family:'宋体';font-size:10.5pt;">当前用户主目录</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">HISTSIZE	</span><span
        style="font-family:'宋体';font-size:10.5pt;">历史记录数</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">LOGNAME	</span><span
        style="font-family:'宋体';font-size:10.5pt;">当前用户的登录名</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">HOSTNAME	</span><span
        style="font-family:'宋体';font-size:10.5pt;">指主机的名称</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">SHELL	</span><span
        style="font-family:'宋体';font-size:10.5pt;">前用户</span><span
        style="font-family:'Calibri';font-size:10.5pt;">Shell</span><span
        style="font-family:'宋体';font-size:10.5pt;">类型</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">LANG	</span><span
        style="font-family:'宋体';font-size:10.5pt;">语言相关的环境变量，多语言可以修改此环境变量</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">MAIL	</span><span
        style="font-family:'宋体';font-size:10.5pt;">当前用户的邮件存放目录</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">PWD	</span><span style="font-family:'宋体';font-size:10.5pt;">当前目录</span>
</p>
<p style="text-indent: 0pt;"><span style="font-family:'Calibri';font-size:10.5pt;">env</span><span
        style="font-family:'宋体';font-size:10.5pt;">命令显示的变量只是环境变量，系统预设的变量其实还有很多，你可以使用</span><span
        style="font-family:'Calibri';font-size:10.5pt;">set</span><span style="font-family:'宋体';font-size:10.5pt;">命令把系统预设的全部变量都显示出来</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_11.png"></span></p>
<p><span style="font-family:'宋体';font-size:10.5pt;">限于篇幅，笔者在上例中并没有把所有显示结果都截图</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。set</span><span style="font-family:'宋体';font-size:10.5pt;">不仅可以显示系统预设的变量，也可以连同用户自定义的变量显示出来</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span style="font-family:'宋体';font-size:10.5pt;">用户自定义变量？是的，用户自己同样可以定义变量</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_21.png"></span></p>
<p><span style="font-family:'宋体';font-size:10.5pt;">虽然你可以自定义变量，但是该变量只能在当前</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span style="font-family:'宋体';font-size:10.5pt;">中生效，不信你再登录一个</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span
        style="font-family:'宋体';font-size:10.5pt;">试试？</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_22.png"></span></p>
<p><span style="font-family:'宋体';font-size:10.5pt;">使用</span><span
        style="font-family:'Calibri';font-size:10.5pt;">bash</span><span style="font-family:'宋体';font-size:10.5pt;">命令即可再打开一个</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span style="font-family:'宋体';font-size:10.5pt;">，此时先前设置的</span><span
        style="font-family:'Calibri';font-size:10.5pt;">myname</span><span style="font-family:'宋体';font-size:10.5pt;">变量已经不存在了，退出当前</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span style="font-family:'宋体';font-size:10.5pt;">回到原来的</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span
        style="font-family:'宋体';font-size:10.5pt;">，</span><span
        style="font-family:'Calibri';font-size:10.5pt;">myname</span><span style="font-family:'宋体';font-size:10.5pt;">变量还在</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span style="font-family:'宋体';font-size:10.5pt;">那要想设置的变量一直生效怎么办？有两种情况：</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">1</span><span
        style="font-family:'宋体';font-size:10.5pt;">）</span><span
        style="font-family:'Calibri';font-size:10.5pt;"> </span><span style="font-family:'宋体';font-size:10.5pt;">要想系统内所有用户登录后都能使用该变量</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">	</span><span
        style="font-family:'宋体';font-size:10.5pt;">需要在</span><span style="font-family:'Calibri';font-size:10.5pt;">/etc/profile</span><span
        style="font-family:'宋体';font-size:10.5pt;">文件最末行加入</span><span style="font-family:'Calibri';font-size:10.5pt;"> “export  myname=Aming” </span><span
        style="font-family:'宋体';font-size:10.5pt;">然后运行</span><span style="font-family:'Calibri';font-size:10.5pt;">”source /etc/profile”</span><span
        style="font-family:'宋体';font-size:10.5pt;">就可以生效了</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span
        style="font-family:'宋体';font-size:10.5pt;">此时你再运行</span><span style="font-family:'Calibri';font-size:10.5pt;">bash</span><span
        style="font-family:'宋体';font-size:10.5pt;">命令或者直接</span><span style="font-family:'Calibri';font-size:10.5pt;">su - test</span><span
        style="font-family:'宋体';font-size:10.5pt;">账户看看</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_23.png"></span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">2</span><span style="font-family:'宋体';font-size:10.5pt;">）只想让当前用户使用该变量</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">	</span><span style="font-family:'宋体';font-size:10.5pt;">需要在用户主目录下的</span><span
        style="font-family:'Calibri';font-size:10.5pt;">.bashrc</span><span style="font-family:'宋体';font-size:10.5pt;">文件最后一行加入</span><span
        style="font-family:'Calibri';font-size:10.5pt;">“export  myname=Aming” </span><span
        style="font-family:'宋体';font-size:10.5pt;">然后运行</span><span style="font-family:'Calibri';font-size:10.5pt;">”source .bashrc”</span><span
        style="font-family:'宋体';font-size:10.5pt;">就可以生效了</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span
        style="font-family:'宋体';font-size:10.5pt;">这时候再登录</span><span style="font-family:'Calibri';font-size:10.5pt;">test</span><span
        style="font-family:'宋体';font-size:10.5pt;">账户，</span><span style="font-family:'Calibri';font-size:10.5pt;">myname</span><span
        style="font-family:'宋体';font-size:10.5pt;">变量则不会生效了</span><span style="font-family:'Calibri';font-size:10.5pt;">。</span><span
        style="font-family:'宋体';font-size:10.5pt;">上面用的</span><span style="font-family:'Calibri';font-size:10.5pt;">source</span><span
        style="font-family:'宋体';font-size:10.5pt;">命令的作用是，讲目前设定的配置刷新，即不用注销再登录也能生效</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">	</span><span style="font-family:'宋体';font-size:10.5pt;">笔者在上例中使用</span><span
        style="font-family:'Calibri';font-size:10.5pt;">”myname=Aming”</span><span
        style="font-family:'宋体';font-size:10.5pt;">来设置变量</span><span style="font-family:'Calibri';font-size:10.5pt;">myname</span><span
        style="font-family:'宋体';font-size:10.5pt;">，那么在</span><span style="font-family:'Calibri';font-size:10.5pt;">linux</span><span
        style="font-family:'宋体';font-size:10.5pt;">下设置自定义变量有哪些规则呢？</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">a. </span><span style="font-family:'宋体';font-size:10.5pt;">设定变量的格式为</span><span
        style="font-family:'Calibri';font-size:10.5pt;">”a=b”</span><span
        style="font-family:'宋体';font-size:10.5pt;">，其中</span><span
        style="font-family:'Calibri';font-size:10.5pt;">a</span><span
        style="font-family:'宋体';font-size:10.5pt;">为变量名，</span><span
        style="font-family:'Calibri';font-size:10.5pt;">b</span><span style="font-family:'宋体';font-size:10.5pt;">为变量的内容，等号两边不能有空格；</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">b. </span><span style="font-family:'宋体';font-size:10.5pt;">变量名只能由英</span><span
        style="font-family:'Calibri';font-size:10.5pt;">、</span><span style="font-family:'宋体';font-size:10.5pt;">数字以及下划线组成，而且不能以数字开头；</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">c. </span><span style="font-family:'宋体';font-size:10.5pt;">当变量内容带有特殊字符（如空格）时，需要加上单引号；</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_24.png"></span></p>
<p><span style="font-family:'宋体';font-size:10.5pt;">有一种情况，需要你注意，就是变量内容中本身带有单引号，这就需要用到双引号了</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_25.png"></span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">d. </span><span style="font-family:'宋体';font-size:10.5pt;">如果变量内容中需要用到其他命令运行结果则可以使用反引号；</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_26.png"></span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">e. </span><span style="font-family:'宋体';font-size:10.5pt;">变量内容可以累加其他变量的内容，需要加双引号；</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_27.png"></span></p>
<p><span style="font-family:'宋体';font-size:10.5pt;">在这里如果你不小心把双引号加错为单引号，将得不到你想要的结果</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_28.png">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">	</span><span style="font-family:'宋体';font-size:10.5pt;">在前面的例子中笔者多次使用了</span><span
        style="font-family:'Calibri';font-size:10.5pt;">bash</span><span style="font-family:'宋体';font-size:10.5pt;">命令，如果在当前</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span
        style="font-family:'宋体';font-size:10.5pt;">中运行</span><span
        style="font-family:'Calibri';font-size:10.5pt;">bash</span><span style="font-family:'宋体';font-size:10.5pt;">指令后，则会进入一个新的</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span
        style="font-family:'宋体';font-size:10.5pt;">，这个</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span style="font-family:'宋体';font-size:10.5pt;">就是原来</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span
        style="font-family:'宋体';font-size:10.5pt;">的子</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span style="font-family:'宋体';font-size:10.5pt;">了，不妨你用</span><span
        style="font-family:'Calibri';font-size:10.5pt;">pstree</span><span style="font-family:'宋体';font-size:10.5pt;">指令来查看一下</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_29.png">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_44.png">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_45.png">。</span></p>
<p style="text-indent: 21pt;"><span style="font-family:'宋体';font-size:10.5pt;">前面光讲如何设置变量，如果想取消某个变量怎么办？只要输入</span><span
        style="font-family:'Calibri';font-size:10.5pt;">”unset  </span><span style="font-family:'宋体';font-size:10.5pt;">变量名</span><span
        style="font-family:'Calibri';font-size:10.5pt;">”</span><span
        style="font-family:'宋体';font-size:10.5pt;">即可</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_46.png"></span></p>
<p><span style="font-family:'宋体';font-size:10.5pt;">用</span><span style="font-family:'Calibri';font-size:10.5pt;">unset  abc</span><span
        style="font-family:'宋体';font-size:10.5pt;">后，再</span><span style="font-family:'Calibri';font-size:10.5pt;">echo  $abc</span><span
        style="font-family:'宋体';font-size:10.5pt;">则不再输出任何内容</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><b>【</b></span><span
        style="font-family:'宋体';font-size:10.5pt;"><b>系统环境变量与个人环境变量的配置文件</b></span><span
        style="font-family:'Calibri';font-size:10.5pt;"><b>】</b></span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">	</span><span style="font-family:'宋体';font-size:10.5pt;">上面讲了很多系统的变量，那么在</span><span
        style="font-family:'Calibri';font-size:10.5pt;">linux</span><span style="font-family:'宋体';font-size:10.5pt;">系统中，这些变量被存到了哪里呢，为什么用户一登陆</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span style="font-family:'宋体';font-size:10.5pt;">就自动有了这些变量呢？</span>
</p>
<p style="text-indent: -5pt;margin-left: 5pt;"><span style="font-family:'Calibri';font-size:10.5pt;"><b>		/etc/profile</b></span><span
        style="font-family:'Calibri';font-size:10.5pt;"> </span><span style="font-family:'宋体';font-size:10.5pt;">：这个文件预设了几个重要的变量，例如</span><span
        style="font-family:'Calibri';font-size:10.5pt;">PATH, USER, LOGNAME, MAIL, INPUTRC, HOSTNAME, HISTSIZE, umas</span><span
        style="font-family:'宋体';font-size:10.5pt;">等等</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p style="text-indent: 15pt;margin-left: 5pt;"><span style="font-family:'Calibri';font-size:10.5pt;"><b>/etc/bashrc </b></span><span
        style="font-family:'宋体';font-size:10.5pt;">：这个文件主要预设</span><span
        style="font-family:'Calibri';font-size:10.5pt;">umask</span><span
        style="font-family:'宋体';font-size:10.5pt;">以及</span><span
        style="font-family:'Calibri';font-size:10.5pt;">PS1。</span><span
        style="font-family:'宋体';font-size:10.5pt;">这个</span><span
        style="font-family:'Calibri';font-size:10.5pt;">PS1</span><span style="font-family:'宋体';font-size:10.5pt;">就是我们在敲命令时，前面那串字符了，例如笔者的</span><span
        style="font-family:'Calibri';font-size:10.5pt;">linux</span><span
        style="font-family:'宋体';font-size:10.5pt;">系统</span><span
        style="font-family:'Calibri';font-size:10.5pt;">PS1</span><span
        style="font-family:'宋体';font-size:10.5pt;">就是</span><span style="font-family:'Calibri';font-size:10.5pt;"> [root@localhost ~]# </span><span
        style="font-family:'宋体';font-size:10.5pt;">，你不妨看一下</span><span style="font-family:'Calibri';font-size:10.5pt;">PS1</span><span
        style="font-family:'宋体';font-size:10.5pt;">的值</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p style="text-indent: -5pt;margin-left: 5pt;"><span style="font-family:'Calibri';font-size:10.5pt;"><img
        src="12_47.png"></span></p>
<p style="text-indent: -5pt;margin-left: 5pt;"><span style="font-family:'Calibri';font-size:10.5pt;">\u</span><span
        style="font-family:'宋体';font-size:10.5pt;">就是用户，</span><span
        style="font-family:'Calibri';font-size:10.5pt;">\h </span><span
        style="font-family:'宋体';font-size:10.5pt;">主机名，</span><span
        style="font-family:'Calibri';font-size:10.5pt;"> \W </span><span style="font-family:'宋体';font-size:10.5pt;">则是当前目录，</span><span
        style="font-family:'Calibri';font-size:10.5pt;">\$</span><span
        style="font-family:'宋体';font-size:10.5pt;">就是那个</span><span
        style="font-family:'Calibri';font-size:10.5pt;">’#’</span><span style="font-family:'宋体';font-size:10.5pt;">了，如果是普通用户则显示为</span><span
        style="font-family:'Calibri';font-size:10.5pt;">’$’</span></p>
<p style="text-indent: -5pt;margin-left: 5pt;"><span
        style="font-family:'Calibri';font-size:10.5pt;">		</span><span style="font-family:'宋体';font-size:10.5pt;">除了两个系统级别的配置文件外，每个用户的主目录下还有几个这样的隐藏文件：</span>
</p>
<p style="text-indent: -5pt;margin-left: 5pt;"><span
        style="font-family:'Calibri';font-size:10.5pt;"><b>.bash_profile</b></span><span
        style="font-family:'Calibri';font-size:10.5pt;"> </span><span style="font-family:'宋体';font-size:10.5pt;">：定义了用户的个人化路径与环境变量的文件名称</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span style="font-family:'宋体';font-size:10.5pt;">每个用户都可使用该文件输入专用于自己使用的</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span
        style="font-family:'宋体';font-size:10.5pt;">信息</span><span
        style="font-family:'Calibri';font-size:10.5pt;">,</span><span
        style="font-family:'宋体';font-size:10.5pt;">当用户登录时</span><span
        style="font-family:'Calibri';font-size:10.5pt;">,</span><span style="font-family:'宋体';font-size:10.5pt;">该文件仅仅执行一次</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p style="text-indent: -5pt;margin-left: 5pt;"><span
        style="font-family:'Calibri';font-size:10.5pt;"><b>.bashrc</b></span><span
        style="font-family:'Calibri';font-size:10.5pt;"> </span><span style="font-family:'宋体';font-size:10.5pt;">：该文件包含专用于你的</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span
        style="font-family:'宋体';font-size:10.5pt;">的</span><span
        style="font-family:'Calibri';font-size:10.5pt;">bash</span><span
        style="font-family:'宋体';font-size:10.5pt;">信息</span><span
        style="font-family:'Calibri';font-size:10.5pt;">,</span><span style="font-family:'宋体';font-size:10.5pt;">当登录时以及每次打开新的</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span
        style="font-family:'宋体';font-size:10.5pt;">时</span><span
        style="font-family:'Calibri';font-size:10.5pt;">,</span><span
        style="font-family:'宋体';font-size:10.5pt;">该该文件被读取</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span style="font-family:'宋体';font-size:10.5pt;">例如你可以将用户自定义的</span><span
        style="font-family:'Calibri';font-size:10.5pt;">alias</span><span style="font-family:'宋体';font-size:10.5pt;">或者自定义变量写到这个文件中</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p style="text-indent: -5pt;margin-left: 5pt;"><span
        style="font-family:'Calibri';font-size:10.5pt;"><b>.bash_history</b></span><span
        style="font-family:'Calibri';font-size:10.5pt;"> </span><span style="font-family:'宋体';font-size:10.5pt;">：记录命令历史用的</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p style="text-indent: -5pt;margin-left: 5pt;"><span
        style="font-family:'Calibri';font-size:10.5pt;"><b>.bash_logout </b></span><span
        style="font-family:'宋体';font-size:10.5pt;">：当退出</span><span style="font-family:'Calibri';font-size:10.5pt;">shell</span><span
        style="font-family:'宋体';font-size:10.5pt;">时，会执行该文件</span><span style="font-family:'Calibri';font-size:10.5pt;">。</span><span
        style="font-family:'宋体';font-size:10.5pt;">可以把一些清理的工作放到这个文件中</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p style="text-indent: -5pt;margin-left: 5pt;"><span style="font-family:'Calibri';font-size:10.5pt;">&nbsp;</span></p>
<p style="text-indent: -5pt;margin-left: 5pt;"><span style="font-family:'Calibri';font-size:10.5pt;">【</span><span
        style="font-family:'Calibri';font-size:10.5pt;"><b>linux shell</b></span><span
        style="font-family:'宋体';font-size:10.5pt;"><b>中的特殊符号</b></span><span
        style="font-family:'Calibri';font-size:10.5pt;">】</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">	</span><span style="font-family:'宋体';font-size:10.5pt;">你在学习</span><span
        style="font-family:'Calibri';font-size:10.5pt;">linux</span><span style="font-family:'宋体';font-size:10.5pt;">的过程中，也许你已经接触过某个特殊符号，例如</span><span
        style="font-family:'Calibri';font-size:10.5pt;">”*”</span><span style="font-family:'宋体';font-size:10.5pt;">，它是一个通配符号，代表零个或多个字符或数字</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span style="font-family:'宋体';font-size:10.5pt;">下面笔者就说一说常用到的特殊字符</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><b>1.  * </b></span><span
        style="font-family:'Calibri';font-size:10.5pt;"> </span><span style="font-family:'宋体';font-size:10.5pt;">：代表零个或多个字符或数字</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_48.png"></span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">test</span><span style="font-family:'宋体';font-size:10.5pt;">后面可以没有任何字符，也可以有多个字符，总之有或没有都能匹配出来</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><b>2.  ? </b></span><span
        style="font-family:'Calibri';font-size:10.5pt;"> </span><span style="font-family:'宋体';font-size:10.5pt;">：只代表一个任意的字符</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_49.png"></span></p>
<p><span style="font-family:'宋体';font-size:10.5pt;">不管是数字还是字母，只要是一个都能匹配出来</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><b>3.  # </b></span><span
        style="font-family:'Calibri';font-size:10.5pt;"> </span><span
        style="font-family:'宋体';font-size:10.5pt;">：这个符号在</span><span style="font-family:'Calibri';font-size:10.5pt;">linux</span><span
        style="font-family:'宋体';font-size:10.5pt;">中表示注释说明的意思，即</span><span
        style="font-family:'Calibri';font-size:10.5pt;">”#”</span><span
        style="font-family:'宋体';font-size:10.5pt;">后面的内容</span><span style="font-family:'Calibri';font-size:10.5pt;">linux</span><span
        style="font-family:'宋体';font-size:10.5pt;">忽略掉</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_50.png"></span></p>
<p><span style="font-family:'宋体';font-size:10.5pt;">在命令的开头或者中间插入</span><span
        style="font-family:'Calibri';font-size:10.5pt;">”#” </span><span
        style="font-family:'宋体';font-size:10.5pt;">，</span><span
        style="font-family:'Calibri';font-size:10.5pt;">linux</span><span style="font-family:'宋体';font-size:10.5pt;">都会忽略掉的</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span
        style="font-family:'宋体';font-size:10.5pt;">这个符号在</span><span style="font-family:'Calibri';font-size:10.5pt;">shell</span><span
        style="font-family:'宋体';font-size:10.5pt;">脚本中用的很多</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><b>4.  \ </b></span><span
        style="font-family:'Calibri';font-size:10.5pt;"> </span><span style="font-family:'宋体';font-size:10.5pt;">：脱意字符，将后面的特殊符号（例如</span><span
        style="font-family:'Calibri';font-size:10.5pt;">”*” </span><span style="font-family:'宋体';font-size:10.5pt;">）还原为普通字符</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_51.png"></span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><b>5.  | </b></span><span
        style="font-family:'Calibri';font-size:10.5pt;"> </span><span style="font-family:'宋体';font-size:10.5pt;">：管道符，前面多次说过，它的作用在于将符号前面命令的结果丢给符号后面的命令</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span style="font-family:'宋体';font-size:10.5pt;">这里提到的后面的命令，并不是所有的命令都可以的，一般针对文档操作的命令比较常用，例如</span><span
        style="font-family:'Calibri';font-size:10.5pt;">cat, less, head, tail, grep, cut, sort, wc, uniq, tee, tr, split, sed, awk</span><span
        style="font-family:'宋体';font-size:10.5pt;">等等，其中</span><span style="font-family:'Calibri';font-size:10.5pt;">grep, sed, awk</span><span
        style="font-family:'宋体';font-size:10.5pt;">为正则表达式必须掌握的工具，在后续内容中详细介绍</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">6.  $ </span><span style="font-family:'宋体';font-size:10.5pt;">：除了用于变量前面的标识符外，还有一个妙用，就是和</span><span
        style="font-family:'Calibri';font-size:10.5pt;">’!’</span><span style="font-family:'宋体';font-size:10.5pt;">结合起来使用</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_52.png"></span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">‘!$’</span><span style="font-family:'宋体';font-size:10.5pt;">表示上条命中中最后一个变量（也许称为变量不合适，总之就是上条命令中最后出现的那个东西）例如上边命令最后是</span><span
        style="font-family:'Calibri';font-size:10.5pt;">test.txt</span><span style="font-family:'宋体';font-size:10.5pt;">那么在当前命令下输入</span><span
        style="font-family:'Calibri';font-size:10.5pt;">!$</span><span
        style="font-family:'宋体';font-size:10.5pt;">则代表</span><span style="font-family:'Calibri';font-size:10.5pt;">test.txt。</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><b>1</b></span><span
        style="font-family:'宋体';font-size:10.5pt;"><b>）</b></span><span style="font-family:'Calibri';font-size:10.5pt;"><b>grep</b></span><span
        style="font-family:'Calibri';font-size:10.5pt;"> </span><span style="font-family:'宋体';font-size:10.5pt;">：过滤一个或多个字符，将会在后续内容中详细介绍其用法</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_53.png"></span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><b>2) cut</b></span><span
        style="font-family:'Calibri';font-size:10.5pt;"> </span><span style="font-family:'宋体';font-size:10.5pt;">：截取某一个字段</span>
</p>
<p><span style="font-family:'宋体';font-size:10.5pt;">语法：</span><span style="font-family:'Calibri';font-size:10.5pt;">cut  -d  “</span><span
        style="font-family:'宋体';font-size:10.5pt;">分隔字符</span><span style="font-family:'Calibri';font-size:10.5pt;">”  [-cf] n  </span><span
        style="font-family:'宋体';font-size:10.5pt;">这里的</span><span
        style="font-family:'Calibri';font-size:10.5pt;">n</span><span
        style="font-family:'宋体';font-size:10.5pt;">是数字</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">-d </span><span style="font-family:'宋体';font-size:10.5pt;">：后面跟分隔字符，分隔字符要用双引号括起来</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">-c </span><span style="font-family:'宋体';font-size:10.5pt;">：后面接的是第几个字符</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">-f </span><span style="font-family:'宋体';font-size:10.5pt;">：后面接的是第几个区块</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_54.png"></span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">-d </span><span style="font-family:'宋体';font-size:10.5pt;">后面跟分隔字符，这里使用冒号作为分割字符，</span><span
        style="font-family:'Calibri';font-size:10.5pt;">-f 1 </span><span style="font-family:'宋体';font-size:10.5pt;">就是截取第一段，</span><span
        style="font-family:'Calibri';font-size:10.5pt;">-f</span><span
        style="font-family:'宋体';font-size:10.5pt;">和</span><span
        style="font-family:'Calibri';font-size:10.5pt;">1</span><span style="font-family:'宋体';font-size:10.5pt;">之间的空格可有可无</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_55.png"></span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">-c </span><span style="font-family:'宋体';font-size:10.5pt;">后面可以是</span><span
        style="font-family:'Calibri';font-size:10.5pt;">1</span><span
        style="font-family:'宋体';font-size:10.5pt;">个数字</span><span
        style="font-family:'Calibri';font-size:10.5pt;">n</span><span style="font-family:'宋体';font-size:10.5pt;">，也可以是一个区间</span><span
        style="font-family:'Calibri';font-size:10.5pt;">n1-n2</span><span style="font-family:'宋体';font-size:10.5pt;">，还可以是多个数字</span><span
        style="font-family:'Calibri';font-size:10.5pt;">n1,n2,n3</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_56.png"></span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><b>3) sort</b></span><span
        style="font-family:'Calibri';font-size:10.5pt;"> </span><span
        style="font-family:'宋体';font-size:10.5pt;">：用做排序</span></p>
<p><span style="font-family:'宋体';font-size:10.5pt;">语法：</span><span style="font-family:'Calibri';font-size:10.5pt;">sort  [-t </span><span
        style="font-family:'宋体';font-size:10.5pt;">分隔符</span><span style="font-family:'Calibri';font-size:10.5pt;">]  [-kn1,n2]  [-nru]  </span><span
        style="font-family:'宋体';font-size:10.5pt;">这里的</span><span style="font-family:'Calibri';font-size:10.5pt;">n1 &lt; n2</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">-t </span><span
        style="font-family:'宋体';font-size:10.5pt;">分隔符</span><span
        style="font-family:'Calibri';font-size:10.5pt;"> </span><span
        style="font-family:'宋体';font-size:10.5pt;">：作用跟</span><span
        style="font-family:'Calibri';font-size:10.5pt;">cut</span><span
        style="font-family:'宋体';font-size:10.5pt;">的</span><span
        style="font-family:'Calibri';font-size:10.5pt;">-d</span><span
        style="font-family:'宋体';font-size:10.5pt;">一个意思</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">-n </span><span style="font-family:'宋体';font-size:10.5pt;">：使用纯数字排序</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">-r </span><span style="font-family:'宋体';font-size:10.5pt;">：反向排序</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">-u </span><span
        style="font-family:'宋体';font-size:10.5pt;">：去重复</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">-kn1,n2 </span><span
        style="font-family:'宋体';font-size:10.5pt;">：由</span><span
        style="font-family:'Calibri';font-size:10.5pt;">n1</span><span
        style="font-family:'宋体';font-size:10.5pt;">区间排序到</span><span
        style="font-family:'Calibri';font-size:10.5pt;">n2</span><span style="font-family:'宋体';font-size:10.5pt;">区间，可以只写</span><span
        style="font-family:'Calibri';font-size:10.5pt;">-kn1</span><span
        style="font-family:'宋体';font-size:10.5pt;">，即对</span><span
        style="font-family:'Calibri';font-size:10.5pt;">n1</span><span
        style="font-family:'宋体';font-size:10.5pt;">字段排序</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_57.png"></span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_78.png"></span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_79.png"></span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><b>4) wc</b></span><span
        style="font-family:'Calibri';font-size:10.5pt;"> </span><span style="font-family:'宋体';font-size:10.5pt;">：统计文档的行数</span><span
        style="font-family:'Calibri';font-size:10.5pt;">、</span><span
        style="font-family:'宋体';font-size:10.5pt;">字符数</span><span
        style="font-family:'Calibri';font-size:10.5pt;">、</span><span style="font-family:'宋体';font-size:10.5pt;">词数，常用的选项为：</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">-l </span><span style="font-family:'宋体';font-size:10.5pt;">：统计行数</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">-m </span><span style="font-family:'宋体';font-size:10.5pt;">：统计字符数</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">-w </span><span style="font-family:'宋体';font-size:10.5pt;">：统计词数</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_80.png"></span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><b>5</b></span><span
        style="font-family:'宋体';font-size:10.5pt;"><b>）</b></span><span style="font-family:'Calibri';font-size:10.5pt;"><b> uniq</b></span><span
        style="font-family:'Calibri';font-size:10.5pt;"> </span><span style="font-family:'宋体';font-size:10.5pt;">：去重复的行，笔者常用的选项只有一个：</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">-c </span><span style="font-family:'宋体';font-size:10.5pt;">：统计重复的行数，并把行数写在前面</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_81.png"></span></p>
<p><span style="font-family:'宋体';font-size:10.5pt;">有一点需要注意，在进行</span><span
        style="font-family:'Calibri';font-size:10.5pt;">uniq</span><span style="font-family:'宋体';font-size:10.5pt;">之前，需要先用</span><span
        style="font-family:'Calibri';font-size:10.5pt;">sort</span><span style="font-family:'宋体';font-size:10.5pt;">排序然后才能</span><span
        style="font-family:'Calibri';font-size:10.5pt;">uniq</span><span style="font-family:'宋体';font-size:10.5pt;">，否则你将得不到你想要的，笔者上面的试验当中已经是排序过所以省略掉那步了</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><b>6</b></span><span
        style="font-family:'宋体';font-size:10.5pt;"><b>）</b></span><span style="font-family:'Calibri';font-size:10.5pt;"><b>tee </b></span><span
        style="font-family:'宋体';font-size:10.5pt;">：后跟文件名，类似与重定向</span><span
        style="font-family:'Calibri';font-size:10.5pt;">”&gt;”</span><span style="font-family:'宋体';font-size:10.5pt;">，但是比重定向多了一个功能，在把文件写入后面所跟的文件中的同时，还显示在屏幕上</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_82.png"></span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><b>7</b></span><span
        style="font-family:'宋体';font-size:10.5pt;"><b>）</b></span><span style="font-family:'Calibri';font-size:10.5pt;"><b>tr </b></span><span
        style="font-family:'宋体';font-size:10.5pt;">：替换字符，常用来处理文档中出现的特殊符号，如</span><span
        style="font-family:'Calibri';font-size:10.5pt;">DOS</span><span style="font-family:'宋体';font-size:10.5pt;">文档中出现的</span><span
        style="font-family:'Calibri';font-size:10.5pt;">^M</span><span
        style="font-family:'宋体';font-size:10.5pt;">符号</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span style="font-family:'宋体';font-size:10.5pt;">常用的选项有两个：</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">-d </span><span style="font-family:'宋体';font-size:10.5pt;">：删除某个字符，</span><span
        style="font-family:'Calibri';font-size:10.5pt;">-d </span><span style="font-family:'宋体';font-size:10.5pt;">后面跟要删除的字符</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">-s </span><span style="font-family:'宋体';font-size:10.5pt;">：把重复的字符去掉</span>
</p>
<p><span style="font-family:'宋体';font-size:10.5pt;">最常用的就是把小写变大写：</span><span
        style="font-family:'Calibri';font-size:10.5pt;"> tr  ‘[a-z]’ ‘[A-Z]’</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_83.png"></span></p>
<p><span style="font-family:'宋体';font-size:10.5pt;">当然替换一个字符也是完全可以的</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_84.png"></span></p>
<p><span style="font-family:'宋体';font-size:10.5pt;">不过替换</span><span
        style="font-family:'Calibri';font-size:10.5pt;">、</span><span style="font-family:'宋体';font-size:10.5pt;">删除以及去重复都是针对一个字符来讲的，有一定局限性</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span style="font-family:'宋体';font-size:10.5pt;">如果是针对一个字符串就不再管用了，所以笔者建议只是简单了解这个</span><span
        style="font-family:'Calibri';font-size:10.5pt;">tr</span><span style="font-family:'宋体';font-size:10.5pt;">即可，以后你还会学到更多可以实现针对字符串操作的工具</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_85.png"></span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><b>8</b></span><span
        style="font-family:'宋体';font-size:10.5pt;"><b>）</b></span><span style="font-family:'Calibri';font-size:10.5pt;"><b>split </b></span><span
        style="font-family:'宋体';font-size:10.5pt;">：切割文档，常用选项：</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">-b </span><span style="font-family:'宋体';font-size:10.5pt;">：依据大小来分割文档，单位为</span><span
        style="font-family:'Calibri';font-size:10.5pt;">byte</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_86.png"></span></p>
<p><span style="font-family:'宋体';font-size:10.5pt;">格式如上例，后面的</span><span
        style="font-family:'Calibri';font-size:10.5pt;">passwd</span><span style="font-family:'宋体';font-size:10.5pt;">为分割后文件名的前缀，分割后的文件名为</span><span
        style="font-family:'Calibri';font-size:10.5pt;">passwdaa, passwdab, passwdac … </span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">-l </span><span style="font-family:'宋体';font-size:10.5pt;">：依据行数来分割文档</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_87.png"></span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><b>6.  </b></span><span
        style="font-family:'宋体';font-size:10.5pt;"><b>；</b></span><span
        style="font-family:'Calibri';font-size:10.5pt;"> </span><span
        style="font-family:'宋体';font-size:10.5pt;">：分号</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span style="font-family:'宋体';font-size:10.5pt;">平时我们都是在一行中敲一个命令，然后回车就运行了，那么想在一行中运行两个或两个以上的命令如何呢？则需要在命令之间加一个</span><span
        style="font-family:'Calibri';font-size:10.5pt;">”;”</span><span
        style="font-family:'宋体';font-size:10.5pt;">了</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_88.png"></span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><b>7. ~</b></span><span
        style="font-family:'Calibri';font-size:10.5pt;"> </span><span style="font-family:'宋体';font-size:10.5pt;">：用户的家目录，如果是</span><span
        style="font-family:'Calibri';font-size:10.5pt;">root</span><span
        style="font-family:'宋体';font-size:10.5pt;">则是</span><span
        style="font-family:'Calibri';font-size:10.5pt;"> /root </span><span style="font-family:'宋体';font-size:10.5pt;">，普通用户则是</span><span
        style="font-family:'Calibri';font-size:10.5pt;"> /home/username</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_89.png"></span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><b>8. &amp; </b></span><span
        style="font-family:'宋体';font-size:10.5pt;">：如果想把一条命令放到后台执行的话，则需要加上这个符号</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span style="font-family:'宋体';font-size:10.5pt;">通常用于命令运行时间非常长的情况</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_90.png"></span></p>
<p><span style="font-family:'宋体';font-size:10.5pt;">使用</span><span
        style="font-family:'Calibri';font-size:10.5pt;">jobs</span><span style="font-family:'宋体';font-size:10.5pt;">可以查看当前</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span style="font-family:'宋体';font-size:10.5pt;">中后台执行的任务</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span
        style="font-family:'宋体';font-size:10.5pt;">用</span><span
        style="font-family:'Calibri';font-size:10.5pt;">fg</span><span style="font-family:'宋体';font-size:10.5pt;">可以调到前台执行</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span
        style="font-family:'宋体';font-size:10.5pt;">这里的</span><span
        style="font-family:'Calibri';font-size:10.5pt;">sleep</span><span style="font-family:'宋体';font-size:10.5pt;">命令就是休眠的意思，后面跟数字，单位为秒，常用语循环的</span><span
        style="font-family:'Calibri';font-size:10.5pt;">shell</span><span
        style="font-family:'宋体';font-size:10.5pt;">脚本中</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_91.png"></span></p>
<p><span style="font-family:'宋体';font-size:10.5pt;">此时你按一下</span><span style="font-family:'Calibri';font-size:10.5pt;">CTRL +z </span><span
        style="font-family:'宋体';font-size:10.5pt;">使之暂停，然后再输入</span><span
        style="font-family:'Calibri';font-size:10.5pt;">bg</span><span style="font-family:'宋体';font-size:10.5pt;">可以再次进入后台执行</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_92.png"></span></p>
<p><span style="font-family:'宋体';font-size:10.5pt;">如果是多任务情况下，想要把任务调到前台执行的话，</span><span
        style="font-family:'Calibri';font-size:10.5pt;">fg</span><span style="font-family:'宋体';font-size:10.5pt;">后面跟任务号，任务号可以使用</span><span
        style="font-family:'Calibri';font-size:10.5pt;">jobs</span><span
        style="font-family:'宋体';font-size:10.5pt;">命令得到</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_93.png"></span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">9. </span><span
        style="font-family:'Calibri';font-size:10.5pt;"><b>&gt;, &gt;&gt;, 2&gt;, 2&gt;&gt;</b></span><span
        style="font-family:'Calibri';font-size:10.5pt;"> </span><span style="font-family:'宋体';font-size:10.5pt;">：前面讲过重定向符号</span><span
        style="font-family:'Calibri';font-size:10.5pt;">&gt; </span><span
        style="font-family:'宋体';font-size:10.5pt;">以及</span><span style="font-family:'Calibri';font-size:10.5pt;">&gt;&gt;　</span><span
        style="font-family:'宋体';font-size:10.5pt;">分别表示取代和追加的意思，然后还有两个符号就是这里的</span><span
        style="font-family:'Calibri';font-size:10.5pt;">2&gt; </span><span
        style="font-family:'宋体';font-size:10.5pt;">和</span><span style="font-family:'Calibri';font-size:10.5pt;"> 2&gt;&gt;　</span><span
        style="font-family:'宋体';font-size:10.5pt;">分别表示错误重定向和错误追加重定向，当我们运行一个命令报错时，报错信息会输出到当前的屏幕，如果想重定向到一个文本里，则要用</span><span
        style="font-family:'Calibri';font-size:10.5pt;">2&gt;</span><span
        style="font-family:'宋体';font-size:10.5pt;">或者</span><span style="font-family:'Calibri';font-size:10.5pt;">2&gt;&gt;。</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_94.png"></span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><b>10. [ ]</b></span><span
        style="font-family:'Calibri';font-size:10.5pt;"> </span><span style="font-family:'宋体';font-size:10.5pt;">：中括号，中间为字符组合，代表中间字符中的任意一个</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_95.png"></span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><b>11.  &amp;&amp; </b></span><span
        style="font-family:'宋体';font-size:10.5pt;"><b>与</b></span><span style="font-family:'Calibri';font-size:10.5pt;"><b> || </b></span>
</p>
<p><span style="font-family:'宋体';font-size:10.5pt;">在上面刚刚提到了分号，用于多条命令间的分隔符</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span><span style="font-family:'宋体';font-size:10.5pt;">另外还有两个可以用于多条命令中间的特殊符号，那就是</span><span
        style="font-family:'Calibri';font-size:10.5pt;"> “&amp;&amp;”</span><span
        style="font-family:'宋体';font-size:10.5pt;">和</span><span
        style="font-family:'Calibri';font-size:10.5pt;">”||”。</span><span style="font-family:'宋体';font-size:10.5pt;">下面笔者把这几种情况全列出：</span>
</p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">1)  command1 ; command2</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">2)  command1 &amp;&amp; command2</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;">3)  command1 || command2</span></p>
<p><span style="font-family:'宋体';font-size:10.5pt;">使用</span><span
        style="font-family:'Calibri';font-size:10.5pt;">”;”</span><span
        style="font-family:'宋体';font-size:10.5pt;">时，不管</span><span style="font-family:'Calibri';font-size:10.5pt;">command1</span><span
        style="font-family:'宋体';font-size:10.5pt;">是否执行成功都会执行</span><span
        style="font-family:'Calibri';font-size:10.5pt;">command2</span><span style="font-family:'宋体';font-size:10.5pt;">；</span><span
        style="font-family:'Calibri';font-size:10.5pt;"> </span><span
        style="font-family:'宋体';font-size:10.5pt;">使用</span><span style="font-family:'Calibri';font-size:10.5pt;">”&amp;&amp;”</span><span
        style="font-family:'宋体';font-size:10.5pt;">时，只有</span><span style="font-family:'Calibri';font-size:10.5pt;">command1</span><span
        style="font-family:'宋体';font-size:10.5pt;">执行成功后，</span><span style="font-family:'Calibri';font-size:10.5pt;">command2</span><span
        style="font-family:'宋体';font-size:10.5pt;">才会执行，否则</span><span style="font-family:'Calibri';font-size:10.5pt;">command2</span><span
        style="font-family:'宋体';font-size:10.5pt;">不执行；使用</span><span style="font-family:'Calibri';font-size:10.5pt;">”||”</span><span
        style="font-family:'宋体';font-size:10.5pt;">时，</span><span style="font-family:'Calibri';font-size:10.5pt;">command1</span><span
        style="font-family:'宋体';font-size:10.5pt;">执行成功后</span><span style="font-family:'Calibri';font-size:10.5pt;">command2 </span><span
        style="font-family:'宋体';font-size:10.5pt;">不执行，否则去执行</span><span
        style="font-family:'Calibri';font-size:10.5pt;">command2</span><span style="font-family:'宋体';font-size:10.5pt;">，总之</span><span
        style="font-family:'Calibri';font-size:10.5pt;">command1</span><span style="font-family:'宋体';font-size:10.5pt;">和</span><span
        style="font-family:'Calibri';font-size:10.5pt;">command2</span><span style="font-family:'宋体';font-size:10.5pt;">总有一条命令会执行</span><span
        style="font-family:'Calibri';font-size:10.5pt;">。</span></p>
<p><span style="font-family:'Calibri';font-size:10.5pt;"><img src="12_96.png">&nbsp;</span></p>

<p style="text-align: justify;"><span style="font-family:'宋体';font-size:10.5pt;">上一页 <a href="11.htm">安装RPM包或者安装源码包</a></span>
</p>
<p style="text-align: justify;"><span style="font-family:'宋体';font-size:10.5pt;">下一页 <a href="13.htm">正则表达式</a></span>
</p>
<p style="text-align: justify;"><span style="font-family:'宋体';font-size:10.5pt;"><a
        href="index.htm">回到主目录</a>&nbsp;</span></p>

</body>
</html>